<%--
  Created by IntelliJ IDEA.
  User: 仲春初九
  Date: 2019/11/20
  Time: 16:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>注册</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="layui/layui.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"  media="all">
    <script src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div style="margin: 0 auto;text-align: center;">
<form class="layui-form" action="" style="text-align: center" id="fm" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">请输入用户名</label>
        <div class="layui-input-block">
            <input id="uname" type="text" name="uname" lay-verify="required" lay-reqtext="用户名不能为空" required
                   placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>

        <div class="layui-form-item">
            <label class="layui-form-label">请输入密码</label>
            <div class="layui-input-block">
                <input type="text" id="upass" name="upass"  lay-verify="title" autocomplete="off" required
                       placeholder="请输入密码" class="layui-input">
            </div>
        </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" value="1" name="usex" title="男" checked>
            <input type="radio" value="0" name="usex" title="女">
        </div>
    </div>

        <div class="layui-inline">
            <label class="layui-form-label">验证日期</label>
            <div class="layui-input-inline">
                <input type="text" name="ubrith" id="date" lay-verify="date" placeholder="yyyy-MM-dd" required
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">请输入手机号</label>
            <div class="layui-input-block">
                <input type="text" name="uphone" lay-verify="title" autocomplete="off"
                       placeholder="请输入手机号" class="layui-input" >
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">请输入地址</label>
            <div class="layui-input-block">
                <input type="text" name="uadress" lay-verify="title" autocomplete="off"
                       placeholder="请输入地址" class="layui-input" >
            </div>
        </div>

        <input type="hidden" value="0" name="utype">
        <input type="hidden" value="0" name="manage">
        <input type="hidden" value="0" name="money">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" onclick="return save()" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <font id="error" style="font-size: 20px;" color="red">${error}</font>
        </div>
    </div>
</form>
</div>
</body>
</html>
<script>

    layui.use(['form', 'laydate'], function() {
        var form = layui.form;
        var laydate = layui.laydate;
        form.render();
        //日期
        laydate.render({
            elem: '#date'
        });

        //自定义验证规则
//        form.verify({
//            uname: function (value) {
//                if (value.length < 1) {
//                    alert("用户名不能为空!");
//                    return false;
//                }
//            }
//    })
    })

    function resetValue(){
        $("#id").val("");
        $("#zoneName").val("");
        $("#description").val("");
    }


    function save(){
        var uname=$("#uname").val();
        var upass=$("#upass").val();
        if(uname==""){
            $("#error").html("昵称不能为空！");
            return false;
        }
        if(upass==""){
            $("#error").html("密码不能为空！");
            return false;
        }
        $.post("${pageContext.request.contextPath}/UserServlet.action",
            $("#fm").serialize()+"&flag=save",
            function(data){
                if(data=="true"){
                    alert("保存成功！");
                    resetValue();
                    window.location="login.jsp"
                }else{
                    alert("保存失败！");
                }
            },
            "text");
    }
</script>